package top.tagao.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import top.tagao.entity.Employee;

import java.util.Calendar;

/**
 * @Author MrXu
 * @Description //TODO $
 * @Date 2021/2/25 19:39
 * @Param $
 * @return $
 */
public class FastJsonDemo {
    public static void main(String[] args) {
        Employee employee = new Employee();
        employee.setNo(1);
        employee.setName("张三");
        employee.setJob("Java⼯程师");
        employee.setSalary(10000f);
        Calendar cal = Calendar.getInstance();
        cal.set(2020,Calendar.FEBRUARY,2,2,2,2);
        employee.setHireDate(cal.getTime());
        employee.setDepartmentName("开发部");

        //把对象转换为json类型
        String json = JSON.toJSONString(employee);
        System.out.println(json);

        //把json转换为java对象
        JSON jsonObject = (JSONObject) JSON.parse(json);
        System.out.println(jsonObject);
    }
}
